** Replication materials for "Female Officeholders and Women's Political Engagement: The Role of Parties"
** Analyses of role model effects on aspirants for party nomination within PAN
** & selection methods of PAN 2015
** Author: Oscar Castorena
** Data: roleModelEffects_Precandidates.dta
** Tables replicated with this do file: Tables 1, 3, A6, A7, A8, A11
** Figures replicated with this do file: 4, 5, A4

* File path of data here
cd "C:\Users\castoro\Documents\"

* set font for figures
graph set window fontface TrebuchetMS

use roleModelEffects_Precandidates.dta, clear

** Probability PAN has female candidate as a function of selection method
eststo clear
eststo: logit pan_woman i.method_desig_baseline, vce(cluster cve_ent)
* latex table (Table 3)
esttab using logitSelect.tex, replace star(+ 0.10 * 0.05) se pr2 label nobaselevels ///
mtitles("PAN Nominee is Woman") varwidth(30) nobaselevels /// 
title("Logit Model of PAN Selecting Woman as Candidate in 2015"\label{tab:logitSelection}) ///
nonotes addnote("Designation by the party is the reference category." ///
"Standard errors in parentheses." "+ \emph{p} $<$ 0.10, * \emph{p} $<$ 0.05") 

** Method selection as a function of electoral performance (t-1)
eststo clear
eststo: mlogit method pan_share_12, vce(cluster cve_ent)
* latex table (Table A11)
esttab using mlogit.tex, replace star(+ 0.10 * 0.05) se label noomitted nonumbers varwidth(30) title("Multinomial Logit of PAN Selection Method in 2015"\label{tab:mlogitResults}) ///
nonotes addnote("Closed Primary is the reference category." "Standard errors in parentheses." "+ \emph{p} $<$ 0.10, * \emph{p} $<$ 0.05") 
margins, at(pan_share_12=(.05(.05).5))
* figure (Fig. 5)
marginsplot, recast(line) scheme(s1mono) xtitle("PAN share of district vote 2012") xscale(titlegap(2)) ///
ytitle("Predicted Probability") title("") ciopts(recast(rarea)) ///
plot4opts(lcolor(sienna) lwidth(medium) lpattern(solid)) plot3opts(lcolor(gs3) lwidth(medthick) lpattern(dash)) ///
plot2opts(lcolor(gs7) lwidth(medium) lpattern(longdash_dot)) plot1opts(lcolor(edkblue) lwidth(medium) lpattern(vshortdash)) ///
ci4opts(color("213 94 0")) ci3opts(color(gs6)) ci2opts(color(gs10)) ci1opts(color(emidblue)) ///
legend(order(5 "Open Primary" 6 "Woman-Reserved Primary" 7 "Designation" 8 "Closed Primary") span)
graph export "mlogit.pdf", as(pdf) replace

** Distribution of PAN support in 2012 (Fig. A4)
hist pan_share_12, start(0) width(.025) freq scheme(plotplainblind) color(gray)
graph export "panShare12.pdf", as(pdf) replace

** Poisson models of number of pre-candidates (men and women) 
eststo clear
* women
eststo: poisson pan_precand_women woman_win_lag pct_women_neighbors_sl pan_safe women_workforce_pct
margins, at(woman_win_lag=(0(1)1) pct_women_neighbors_sl=.29 pan_safe=0)
* for plot
marginsplot, recast(scatter) scheme(s2mono) graphregion(color(white)) yscale(range(.4 1.9)) xscale(range(-.5 1.5) titlegap(3)) xtitle("Woman won district (t-1)", size(medlarge)) ///
title("Women", size(large)) ytitle("Predicted No. of Precandidates", size(medlarge)) plotopts(msymbol(circle) mcolor(black)) ylab(.4(.2)1.8) ciopts(recast(pcspike)) saving(womenNum, replace)
* men
eststo: poisson pan_precand_men woman_win_lag pct_women_neighbors_sl pan_safe women_workforce_pct if reserve == "mixed"
margins, at(woman_win_lag=(0(1)1) pct_women_neighbors_sl=.29 pan_safe=0)
* for plot
marginsplot, recast(scatter) scheme(s2mono) graphregion(color(white)) yscale(range(.4 1.9)) xscale(range(-.5 1.5) titlegap(3)) xtitle("Woman won district (t-1)", size(medlarge)) ///
title("Men", size(large)) ytitle("Predicted No. of Precandidates", size(medlarge)) plotopts(msymbol(circle) mcolor(black)) ylab(.4(.2)1.8) ciopts(recast(pcspike)) saving(menNum, replace)
* Role model effects on aspirants for party nomination (Fig. 4) 
graph combine womenNum.gph menNum.gph, scheme(s1mono) scale(1.3)
graph export precandCount.pdf, as(pdf) replace
* latex table (Table 1)
esttab using countModelW.tex, replace star(+ 0.10 * 0.05) se pr2 label eqlabels(none) varwidth(35) mtitles("No. of Women" "No. of Men") ///
title("Poisson Model of Number of Pre-Candidates in a District"\label{tab:aspirantResults})

** Poisson model of number of female pre-candidates (controlling for women-only primary)
eststo clear
eststo: poisson pan_precand_women woman_win_lag pct_women_neighbors_sl pan_safe women_workforce_pct women_only
*latex table (Table A6)
esttab using countModelW_robust.tex, replace star(+ 0.10 * 0.05) se pr2 label eqlabels(none) varwidth(35) mtitles("No. of Women") ///
title("Poisson Model of Number of Pre-Candidates in a District: Excluding Districts with Women-Only Primaries"\label{tab:aspirantResultsRobust})

** Poisson model of number of female pre-candidates (PAN-specific independent variables)
eststo clear
eststo: poisson pan_precand_women pan_woman_win_lag pan_wom_neighbor_lag pan_safe women_workforce_pct
* latex table (Table A7)
esttab using countModelWpan.tex, replace star(+ 0.10 * 0.05) se pr2 label eqlabels(none) varwidth(35) mtitles("No. of Women") ///
title("Poisson Model of Number of Pre-Candidates in a District"\label{tab:aspirantResultsPAN})

* Descriptive stats of precandidate analyses (Table A8)
eststo clear
estpost summ pan_precand_women pan_precand_men woman_win_lag pct_women_neighbors_sl pan_safe women_workforce_pct
esttab using descriptivestatsPAN.tex, cell("mean(fmt(%12.2f)) sd(fmt(%12.2f)) min(fmt(%12.0f)) max(fmt(%12.0f)) count(fmt(%12.0f))") nonumber nomtitle noobs label replace ///
title("Descriptive Statistics for PAN 2015 Candidate Selection and Primaries Analyses"\label{tab:panDescStats}) 


